rewrite program with more count of headers