Fixed reaching an out of bounds error when opening file