refactor module internals

Since the many changes the modules have experienced it is necessary to rewrite some of them to make them more readable, shorter and error proven.

First refactor is around WebSocketUpgrade (error management is currently missing).