Improve dialect handling, simplify code