refactor condition calculator