Fixed memory leak. Thanks to Mark Magnusson