Refactor and extend to handle any content type