Wrote some integration tests, and fixed a nasty bug in stop() behaviour.