major refactor of js