refactor three methods into one