Support custom wait and stop functions.
Merge pull request #14 from dnephin/custom_wait_and_stop

Support custom wait and stop functions