refactored the implementation of how a console application can handle events