add comments, fix a few bugs, update readme