some comments, as well as checking for invalid input