Added sorting of entries to avoid deadlock situations