branching retrieving logic into separate function