implemented loading algorithm