added loop code