Refactored code to follow guidelines