Ensure glfwInit is only called once and glfwTerminate is called even after task failure.

This also removes the need for the glfw::terminate function