Revert "Streamline error handling and locking" (fixes #172)

This reverts commit 116f232f5a20ca0e4d61f776c99e9a10b1cfa8dc.
Revert "Fix protocol close test"

This reverts commit 92c1ce57a698d6e45388a403557b592191ad46f3.