improved readability and added comments (2)