major logic fixes