PEP8, clean code and little speed-up.

I've reorganized some code to get it clean and removed a couple of unnesesary range creations.