check if val is defined before overwriting
Merge pull request #16 from antham/master

check if val is defined before overwriting