Initial commit

Initial commit of the function as a whole.