Several fixes in order to get maliit working correctly

See commit messages for a description of the different changes.