Refactor loader.py for readability