added socket connection handling