Fix bugs introduced by previous refactoring