Added a way to avoid globals for #1274. Example usage is yet TODO.