Refactor sync and sockets