Better null checking when resolving references

Review URL: https://chromiumcodereview.appspot.com//65043010