fixed some segfaults on memcpys.  Also added in some ugly debugging code that will need to be cleaned up.