CFY-1840 minor fixes and refactoring.
CFY-1840 flake8