Refactored text-writing into a new function