added ID gen code
tidying up