Move heavy functions to JS