Adding null value check to merging code