Fix bugs in previous 3 commits