added all code to functions
added all code to functions