Modularize code
Fix UI glitch