improved prefix code to not use regexps