Improvements and code refactoring.

OK.