Clean up some code and add a couple explanatory comments