Bug fix and refactor for ValidatedId method