Large refactoring in order to add Pump.io support. Some errors still
left in the code.