added a counter array

Also added some small changes and some comments