reorder headers and fix resulting errors