refactored refid to have more fields and indexes