Refactoring. Implemented connection handling. Changed callback to be per call.