made modification to count leading 0s