Clean up some code and add a couple validations.