Refactor the bias measuring code