All test pass now, refactor code