Fix bugs in previous commit