Reverted most of r2865. It introduced several issues and large chunks of new but unmaintained code. A few fixes and improvements that could have stayed are reverted as part of this, but they can be re-added later if necessary.
Authored by: plombo 2010-11-30
Parent: [r2942]
Child: [r2944]