refactored load order function