added better error checking and easier configuration of compression