Remove unused variables
Fix memory leaks on exception
Use pre-increment for iterators

Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.
Merge pull request #60 from mscdex/misc-fixes

Misc fixes