js implementation refined