move db logic from view