adding comments and tests
add comments and fixes