fix a few more bugs, add memset and memcpy
lots of scoping fixes