Moved connection logic into separate file in examples.