Fixed crash problem

Still doesn't get correct result for last test but this is the only test it doesn't pass, and it now runs without crashing.