BUG: change wait function to wait on window events for an interval instead of sleeping for an interval.