fix placement of params and gradient