refactor out gratuitous each loop from add_to_database method