Ugly but working trimming from history