fix logic, a lot of logic