refactor code. in progress

refactoring code into counter. finished decode, working on issue.