derivative code almost done;