Some minor cleanup, getting rid of unused stuff.
Some stab in the dark guesses about memory corruption.