added connection code, also some code cleanups