Resource leak fix. Fixed #8