register count refactor