Fix bug that would run program twice using JM_UI.
Clean up code.