move calculateFragments fragments.R
rewrite calculateFragments