Small logic optimization