Fix and recomprehense the setInterval function