Not working for broken databasemodel
Working version
Cleaned up