Updated comments and improved code