Various fixes (will be rebased)