Added sorting by priority.