Updated SQL for thread_rank
Changed zero based rank to one based rank