Reorganize stream server code