added proper id check + sort order