A lot of fixes for typed logic