Main program working

A lot of debugging, assertions, reworks and redesign