Adding functions

Added all functions and some comments. Tested functions successfully.
Still need to add more comments.
Final version

Added comments