added some comments for readability