improved loading function