Added Gzip support and some refactoring