Code clean up, added comments and corrected indentation