redone the factories to get rid of duplicate code