implemented end function