fixed sort function & improved view
fixed query function