made g a pointer so I can delete it before program finishes execution