Refactor to make regex less evil,