Added unittests moved logic into main.js