Fixed various bugs that made tests fail.