loop logic fix, comments