added "state" machine