Cleaned up some repeating code using factories