First draft of functions. Need to comment.