FIX: more fixes and missing parts from previous merge with master branch.