Tidying and starting on better handling of preferences.
Bug fixes and better preference handling.