add gradient and modified the method of checking the elements