Fixes storing of error messages

- Error messages are now stored correctly.
- Memory buffer is reset prior to copying contents.