Added support for stopping loops