Added proper boundary checking code (thanks to Travis) and played with speed and some other parameters a bit.