Changed to use pattern match in one function