Cleaned up. Supports txt, xml and emp (gzipped xml)