Improve stability.

Change entity strategy.
Fix catch leaks.
improve code quality.