fixed all the logic