Fix remaining bugs and broken tests