restructure js helper functions