refacotry sample code.