I certainly wouldn't try to do the refactoring and optimizing (actually, this is more like a complete new feature) at the same time.
First, make it work, even if it will make the code look ugly. You're not going to save any time by doing both things at the same time. Refactoring something that works is a question of 10 minutes in Visual Studio.
Trying to figure out whether it's the refactor or something else that broke the rendering (if you try to do both things at the same time), takes way more time than those 10 minutes...