mild refactor and wrote an additional test case