now handles invalid inputs