Reverted the manuscript to be run through R only and fixed an issue that
occurred in rare situations