Fixed gre function for longer strings