Small logic fixes