Finished code for solver and preproc