Fixed database warnings and introduced some caching to the preferences
Several small fixes for NPEs etc.