Fix some bugs introduced during refactor