move control code to client scripts