flake 8 fixes with code improvement

fixes for flake8