Rebased and documented with devel roxygen2.