Added sorting, minor fixes.