first refactor from server to device