Fix use of end function