finished conversion to pure javascript