Minor code fixes and pep8 rules applied