Refactoring and little fixes.