moved duplicated code to own method