Separated the hdr generator and the automatic grouping code to own file.