Added check for invalid input