relocated functions, added tests