fixed the bugs in the soring method