refactoring

fixes and refactoring