Added proper comments and documentation for functions.