sorted constructor