ex7/ex8: fixed file parsing logic