Clean up and refactoring