Add code to functions

Added code to functions to make them do what they are supposed to.
Details in comments of code.