moved code into own method