Add commenting, clean up code