Remove some duplicate imports and (mostly) tidy up to PEP8.

Again, think all is well, but would be good for someone else to check over before deploying!