update gradient and offset calculation