Minor refactor to move shared functionality out of rake task