some logic fixes