Severe refactoring using regexp to process lines (and everything else for that matter)