cleaning up and refactoring