cleaner and refactored