compose algo for complex cases