undefined variable error improvements