Refactor context io