Memory bug fix