Fixes #22. Significant refactoring of the code to allow a single base function for both initial deployment and adaptation. It performs appropriate action based on the current ResourceMapping.

Changes to #17 due to refactoring. no known regression. will test again later.

Note: There are synchronization issues w.r.t to the backchannel. But not fixing it now since the messaging infra. is supposed to be updated according to issue #21.