changed open file in loop instead of setup