remove cross-references and subheaders, restructure code a bit