FIX: memory use on encoding