Bug fixes.
Code refactoring.