Fix file opening and make tests pass.