[#637] Pep8 fix
[#637] Bug fixes and code simplifications