adding comments and formatting for easier comprehensibility