changed order of read-in loop