Refactor variables and shorten frequency checking