code adjusted for db move to server-side