Refactoring MQTT Related Flows

Refactored MQTT related flows, improved on the javadocs, fixed some performance related issues