added end and waittoend