Refactor and add fail test