added loop and some comments