Code cleanup and header sorting