Initial refactoring of rendering and tests