more functionality and refactoring