improve loading logic