copied in functions, added documentation and produced .Rd files