Fixed loop to close after 3 times