fixed delay error, removed global function, added correct code in html page