update texture handling to avoid memory leak