further bug fixes after refactoring