Adding tests would be useful in this case and also will be easier to refactor code. We could use [jest](https://jestjs.io/) for testing.