[TASK] Adds unit tests and refactors javascript