Added comments and formatted code