fixed memory leaks (thanks to Jeff Spaulding)