Refactoring and more functionality