Comments and flagged tile update

Added comments and rearranged code for readability

Also changed if statement on line 43 to remove redundancy