refactor long if to switch case, more error messages