added loop to do the complete cycle