finished db insert and update functionality