optimize gradient and speed estimate