added .gz support and refactored
refactored