Fixed bugs found in scope by the unit test (yay!)