Fix #2. Add check for invalid input