Fixed the adaptivity once and for all, however optimization won't work.
Finished merging from branch.