Fixed issue #7, integrated aggregation through event window and refactored the code