modified to use relationship on db
fixed a little bit