Refactor text rendering