add index on metadata ##
add db logging ##