split logic into multiple functions