Added pattern matching and if checks