Fix some memory leaks on model data.

Create cleanupContext method to delete previous model data
along with page navigation.

And some refactoring.