Refactored and cleaned