Added a simple debug facility.
Addedd a finite state machine implementation