more fixes for invalid IDs and the reference function