Added waitforevent function for testing to check for events occurring