Fixed bugs introduced in previous refactoring.