Converted loading into function