scoped pointer to avoid memory leaks

also add a check to make sure we migrate properly to the new merge mined
blocks