added tests, fixed a bug found when writing the tests
Automatic style corrections courtesy of autopep8