Refactored code and conformed to style guidelines