code cleanup
preliminary work for websocket support