Issue #26: Improve error detection
Issue #26: Compact ThreadLock implementations