fixed #3, simplified the sorting...