Cleaned up code in regexp, minor changes to imports etc.
fixed merge conflict