Find and fix some deep bugs