Code simplification, and some cosmetic changes