old js implementation.