refactored count_bin.py