copy in initial implementation from livedb and convert to js