Big clean-up of code