cleanup, implemented defs, added tests