Improve the code a little

The code should function pretty much exactly the same (other than keyboard interrupts).

All I've done is reduce the amount of duplicate code.

I removed the KeyboardInterupt handling as it really isn't needed. The only reason you really need that is if you need to clean things up afterwards.