small logic fixes