Added loading function waiting for resources to load.