Added a clean up method. It still does not behave properly, but substrate gneration is much better