Refined API state framework and added deinitializer for BFIO.