converted to js but incompleted.