Simplified. Several refactors
Some cleanup and refactoring and adding visualization test
Move things to js file