updated residual function; fixed bug in coefficient.c