added some comments and fixed up the test code. Still doesn't test everything