Added bounds checking to the tileAtTouch function.
Some more refactoring to break code into logical blocks.