Track ids at database level
Added reference removal