Added cleanup method to prevent memory leaks