Some more bad code removed. Note that this is not yet tested properly.