Added some documentation to functions and some test code at the end of the file