Cleanup

I've made a few commits aimed at reducing some of the complexity of the code.  It's just a bit of getting my feet wet in your code, but it's a start.  Please review and feel free to leave comments.