Changed back the sorting to lists:sort