Replaced maddening lambda-if-then-else conditional branches with simpler 'case' ones