general code organization improvements

I was reading your code to understand it, and I end up cleaning it up a bit :)