fixed memory leak, thanks to bulk88 for the tip