added TMS state tracking and error messages