Adding handling undefined variables

as discussed, handling for undefined variables added.