improved doc, simplified logic