Refactored and updated load function