adds buf_compact
flips and slices input buffer properly; recognises close frame