remove nil check

calling replace_keys could possibly do a nil check twice, this commit
reduces it to once.
remove more nil checks