Factor out useful code