fixes issue 1400

fix for issue #1400. I also made some pep8-type fixes to lines that I was working on, but not through-out the script.