Rework of logic, almost done!