some more cleanups and locking the factory creation process to one
thread