added more tests, document code