refactor to use delay