UI: Coverity fixes.

Also fix some issues identified by IntelliJ.