Implement copy constructor to prevent malloc errors

Fixes #1