Refactoring, bug fixes.