updated sorting functionality