Use context instead of globals

Change-Id: I8671418fe354f75fc0872f48ffcf171919efdac0