UI code cleanup

Cleaned up UI handling code, fixed lots of bugs with parameter panel.