changed expression logic to if/then/else logic to avoid expr logic inconsistencies and simplify debugging