Optimised by using one dimensional array and writing to a temp array in solver