Same spacing issue. The if should probably be moved inside the setTimeout to reduce duplication