Moved context creation logic to a seperate function