finished backend code