Merged manually with Ben's code
WE MADE STACK GOOOD
WE MADE STACK GOOOD
sanitized ptr and buffers