better js implementation