move some code from server to backend