fixing output loop