Add better ordering logic