Fixing null exceptions because of invalid database data