Memory leak repair and other fun stuff