close to working counting.

slight bugs might be presented.