partially working js-only version