Fixing an issue with undefined variable