This fixes a bunch of bit allocation bugs