Fix issue #1 (really).

Okay, I failed last pull request, but this one should really encapsulate the state machine structure in the C file (fix issue #1).