refactored the build order logic to be more understandable and consistent across the three types of steps