Bug correction (now passing improved permutation test), plus cosmetic changes