Fixed lock issue.

Note: added sleep in run() - might be
cause of future problems?
Added testthat test, closes #25