Added thought sorting func