Cleanup and refactored code