Changed logic and exception message