moved strlen() for prefix out of func. to one-time calculation at the top