Add a connection lock

Fixes #80