Refactor toString method