Better use of setTimeout