fixed some nested if/whens with a typecase