r34: Added unit tests, fixed reg bugs