fix use of function end()