Some refactoring.
Adding preferences.