refactor loader code