Fixed insertion of headers at the end

When using header element types in a page which are not present in the header of the layout template, the merging of the headers results in an ArrayIndexOutOfBoundException. This patch fixes that and inserts "new" header element types to the end of the header.