Refactored code, and indentation