Formatted code and added comments