Some additional memory improvements and bug fix.