refactor mqtt