refactored context generator