implemented as R pacakge