Use Mutex to grant exclusive access to connection

Replaces our current implementation using a standard instance variable. Should make the library safe to use in a threaded environment.