Filter head declarations + cleanup output

Only declare stuff in head that is actually used in body.