minor logic and cosmetic changes