Updated statemachine comments, fixed some minor issues and expanded tests.