Improve use of the "count" variable