added auto_end function