Remove  globals in favor of API wrappers. Fixes #44