Improved R Code, addresses #151.