add tests and refactor job