Rewrote file opening so that content is checked as gziped format first.