Refactore to achieve generalization, moving common parts to IoTpy.core