Not completed, but little optimized whileTerrainLoading function.