move logic to javascript from python