flushSpi now properly closes file handles