includes error control and some nit fixing