Limiting the output rate

The upload rate can now be limited so it does not clog the internet connection.

Only commits 6fb176b, 0419aa6, 229026b and 5ae64de are actually related to the limiting. The rest are refactorings to clean up the code a bit and get it ready for the change!