Fixed some validation and pattern matching issues