Added comments and documentation in the code