refactored unit factory