Code improvement for getString() method