refactor to JS and remove the print statements