changed the loop as @stdweird suggested. Also changed comment