moved code from event handlers to be ran on the FX thread