Fixed bugs caused by refactoring.