Bug Fix for flush and close when called together