code reformated for cran submission