Restore and improve the refactor version