incremental improvement on trim_code