Small code changes to pass tests and CRAN check