Refactored giant if-statement