refactoring and bug fixes