Fixed issue with wrong variable being used