completed conversion to javascript