Added some collision and bounds checking