Overcome Delay problem

There is no code error. You have to learn the techniques that are suggested in the documents that were linked to, in order to do what you are asking. Nobody here is going to just fix your code for you.