tidy up of enumcount function