Commenting, refactoring some duplicated code.