Fixed some bugs that were introduced with the latest refactoring.