Refactored code cleanup