Add debug logging
More robust method of id discovery