Fix leaks

Related to #9. This fixed all the leaks I found in my app.

Please review carefully, as I have not contributed to a non-ARC project for some time.