generalized rtm_id function