change WAIT macro to function