Fixed conversion to logical variables

Final fix for all bugs