Removed undefined behaviour from pattern matching