Added sorting function, backend and frontend