added some comments for clarity