Added flag logic. The state of the tile logic has not been addressed.