cleaned up loose ends, added test cases