fixes bugs after refactoring.