Fixed order of setTimeout and areAllLoaded()