improved loading logic