Fixed handling of currentState, by defining it in each while_state function (since on entrance to that function it can only have the value corresponding to that function) rather than passing it.