added implementation for unknown amount of words