Added comments and some changes to comply with coding standards