extract methods, added tests