Modify find end function