Fixed an intermittent floating point precision problem, added a missing stream closing command.