updated code with support for array of IDs