Closes #190 - Fix all potential resource leaks

Pull request for #190
fixed in a6ce9ec