extraCodeAtEnd parameter added, fixes #329
Add `addCustomCode` to remove duplication
Merge branch 'extraCodeAtEnd'