Several bugfixes, additional assertions and simplifications.
Also renamings and fix for vs120 release mode.