Converted large if block to use dictionary lookup