added eval, test and applygrad functions