added some comments for easier understanding