Fixed more bugs caused by refactoring.