Dynamic compression algorithm