Add comments, expand tests, remove unused code