This code is based on the deheader experimental code in the web version. It is very rough but it works for now.