Added comments and more input sanitation.