Rework logic, some fixes