extract method, added tests