Moved from a long if-else to a switch statement for setting error message