Mining related calls moved.

Also Fixed potential memory leak