changed condition order for optimization