refactor linear search to setInterval