bug fixes from refactoring