refactored the ordering code to static functions;