fix some stupid memory bugs