Refactoring: added the functions AppendToString, ToString and ThrowException