Add unit tests and fix pep8 issues