Minor logic bug fix and additional of NULL to avoid R CMD check warning