moved some code, added tests