Fixing bugs. Memory copy bug fixed. Added small debugging helpers