Bug fixin' and test makin'

See commits for related issues fixed.