Cleaning-up some gui events by placing code into separate function.