changed the way ref no.s are generated