Fixed bugs in loading algorithm and implemented it properly