added issorted flag