change from js setInterval to callback update, refactor code