Fixed Indentation and refactored the code