some cleanup, added tests