Moved this code to schematools
Partially tested, procedure makes sense more or less