more comments, tests, and isValid function