prevent open file handles leak. fixes #9