better lag compensation/code refactoring