Moved ordering code to it's own method