PEP8, using with statements and making the num() function a little more ...

...intuitive.

This doesn't modify any functionality - just cleans up the code a little bit.