small changes for code cleanup / efficiency 

- formatting fixes for PEP8
- removed unused imports
- changed 'range' to use 'xrange' if running under Python 2.x.