Python functionality implemented in Javascript, small details missing