Refactor title extraction code.