misc fixes, now passes R CMD check