changed header
changed count function
added some debug