rewrote everything to class based state engine