fix a bug i introduced last week - need to make a list before sorting.
Following PEP recommendations in various files

Minor, aesthetic changes.