This is not the best way of managing it for sure, but the function does a lot of things at the same time, focusing on `dom.message`. Not sure if it would be better to split it.