Implemented event sorting logic to fix most of the ui bugs