Added sorting and fleshed out some unfinished parts.