Polymormphic type flattening for all types
Tidy up, add function to add new functions to a given program