changing method insert() to work with database