extracted code into three methods