added a test, cleaned up some code