Make entities_to_update and entities_for_input sets.
Use sets for grid squares instead of lists.