refactored regex handling and content encoding removed