Major code clean up