Op create factories

Created abstract factory class and moved closures to factory classes so that the config can be cached