Added 'write_essay' function