Added checks for valid inputs