fixing delay function