Fetching preferences etc from the database. Also other fixes.