Changed db to an argument.