Add codes in saved graph
Refactored codes generation: removed 'randomness', added optimisations