fixing undefined variable error