Redoing this in native javascript for simplicity.