Fix tests and R CMD CHECK