Refactor regex mess