use g_close to close a file descripter opened by g_open
since we can.... since we're in C++ turn on the templated secure overloads, not that it really matters
minor fixes
minor optimization