Fixed UI issues; optimized code