Cosmetics and some logic fixes