extract logic to sub package
update main app to use sub package
move handler as separate func