added stop condition in setInterval