made sorting more intelligent