Patched some bugs introduced in previous commits, to get tests to pass