infinite loop on pattern matching