Minor logic fixes