minor code fixes and clean-up

some problems identified by pyflakes and fixed