Fix bugs introduced by refactoring