Improved the way to find next and previous testcases + removed some unnecessary code