Added extra checks to handle invalid input like '--', 'a', 'a+b'.