Code refactor and update the implementation of isWaitingForNextEvent Change-Id: Ic6f4db7cc91c2e4c18d921704f638cfdc7299e2c