adding some comments and formatting the code