tweaking save function so that it sort too