refactored unit generation and cost testing to single method