a few logic fixes