RM6180

Deadlock fix and off-by-one error.

Fixing unit tests. One-by-one. By one.

Unit tests fixed.