Restructure application code a bit, add event dispatcher