fix the regex, and some sanity checking