Fix some bugs after the major refactor