added compatibility for both .gz and non-.gz files