flattened logic