move function to javarosa
improve output ref regexes