refactor word ladder