Fixing undefined variable error