initial working code.
 Added comments and description for the functions.