improved readability and added comments (3)