Loop bug fixed