Tidy up how invalid ids are handled.