Fix bugs in the new implementation