Large scale refactoring to facilitate fixing rendering quirks
Code cleanup