Major code clean-up