move connection handling to lib/connection!