Add connection throttling

This is not ready for merge!

_We_ need to write tests @marcusramberg - but please comment and review the code.

Sorry for doing refactoring in the same branch, but I had a hard time wrapping my head around the code as it was structured.
These lines without $data are just cleanups.