use ternary in prior foldl as well