rewrite library, added basic tests