Uploading completed functions

Initial commit of file and functions. Completed comments to follow
Added comments

Comments added to explain function. Should be final commit