Fixed to loop round between Z and A. Now passes all system tests
Rewritten using StringBuffer. Now passes all system tests