refactor backend socket/connection handling