fix for wrong variable and logic