Fixed so val returns undefined instead of null.