I'll write a post to explain how works the cycle counter and how you can write your own cycle counter in few days (weeks)...That will be more more simple that triyng to explain part by part how the program works !!!
But your solution is not a good solution... to much work !!!