Major code cleanup and fixed many UI errors