Fix mem leak, minor readability improvements

I find it much easier to follow.