Null check in valueOf

Fix value of function to work with null values.