more refactoring, bug fixes