More updates to grid sorting script

I am closing in on a final grid sorting script, however there are still
some issues with this script, e.g. sorting is still flawed and there is
not much flexibility to the script...