Revert "Moved websocket logic into a loop"

This reverts commit 066a38b3b59bf5309d04a10c066e85e101b1f0e1.
defer websocket close instead of handling explicitly in several places