Add sorting on id function