Code-wise, I would prefer if you move this stuff to a function or class. The main is already pretty cluttered. Personally I prefer a main function that consists of function/method calls, not logic and rendering code in itself.