Added ability for multiple connections and some error control