converted to JavaScript