Fix bug with register counter