Match brackets and set the parent correctly after that