added separate query to pull the latest reference number from the DB