Can someone help me to improve my code? IR remote control to control Motor

Really appreciate for this tip, i think on the example below i won't be able to avoid delay(), so i can create a pause that will make motor works for specific period of time before it will shutdown. Is there any other recommendation can be regarding if i need to make motor runs for a while?
delay