Unify preloading code