fixed bug in loading function