Fixed leaked memory issues