Major code clean-up (incomplete).