Added () to satisfy jshint warnings.
Added missing semicolons.
Added a loop so processEvents is called until either paintEventCalled == true, or until we time out. (5 sec.)