Factor out a more logic into reusable parts