Added connection test and implemented connect()