Refactored context code to a new file