functions slowly for large input