Factor out main