refactored to clean code