Fixed bugs introduced by refactoring