Fixed memory leaks, and a typo in a comment.