Refactor topic preview code
Update and refactor tests