Refactor context loading