Found the typo that caused memory errors in buffer.copy