Cleaned/refactored code