Added makeElementValid functionality and pattern structure