cleaned up my count_reg code to reduce redundancies and become more readable