Refractored UI code to be more modular and did some fixes.