Added loading function. Fixed memory problem.