added gradient code to unit