refactored setTimeout to setInterval