ENH: Code edited to respect PEP8 in several places + renamed some variables not to overshadow others.