rewrite library, adding comments, remove old code