more testing and refactoring of js